<template>
  <div>
    <operation-title
      title="积分"
      :icon="TitleIcon"
    />
    <div class="divider"></div>
    <div class="func">
      <p class="attr">积分设置</p>
      <div class="adjust-item">
        <span>类型展示</span>
        <el-radio-group v-model="config.pageConfig.showType">
          <el-radio label="1">累计积分</el-radio>
          <el-radio label="2">我的积分</el-radio>
        </el-radio-group>
      </div>
      <div class="adjust-item">
        <span>积分字号</span>
        <el-slider v-model="config.pageConfig.integralSize" :min="0" :max="50" show-input size="small" />px
      </div>
      <div class="adjust-item">
        <span>积分颜色</span>
        <el-color-picker v-model="config.pageConfig.integralColor" />
        <span class="color-value">{{ config.pageConfig.integralColor }}</span>
      </div>
      <div class="adjust-item">
        <span>积分跳转</span>
        <el-switch v-model="config.pageConfig.openToLink" :active-value="true" :inactive-value="false" />
        <span v-show="config.pageConfig.openToLink">开启</span>
        <span v-show="!config.pageConfig.openToLink">关闭</span>
      </div>
      <div class="adjust-item" v-if="config.pageConfig.openToLink">
        <div class="link-div" @click="linkDialog(config.pageConfig, 0)">
          <el-icon>
            <Link />
          </el-icon>
          <span style="width: 100%" v-if="config.pageConfig.url">{{
            config.pageConfig.urlName
          }}</span>
          <span v-else style="width: 80px">请选择链接</span>
        </div>
      </div>
      <div class="adjust-item">
        <span>积分规则</span>
        <el-radio-group v-model="config.pageConfig.showIntegralRule">
          <el-radio label="1">显示</el-radio>
          <el-radio label="2">不显示</el-radio>
        </el-radio-group>
      </div>

      <div class="add-item-input" v-if="config.pageConfig.showIntegralRule == 1">
        <p></p>
        <h4>建议图片宽度88px，高度28px</h4>
        <div class="upload-img" v-if="config.pageConfig.imgIntegralRule">
          <el-image style="width: 100%; height: 100%" :src="config.pageConfig.imgIntegralRule" fit="contain"></el-image>
          <div class="upload-img_cover">
            <Upload :model-value="fileList" file-path="act/" :limit="999" :show-file-list="false"
              @success="uploadSuccess">
              <el-button size="small" @click="currentType = 'imgIntegralRule'">替换</el-button>
            </Upload>
          </div>
        </div>
        <Upload v-else v-model="config.pageConfig.imgIntegralRule" file-path="act/" list-type="picture-card">
          <el-icon>
            <Plus />
          </el-icon>
        </Upload>
      </div>
    </div>

    <div class="divider"></div>

    <div class="func">
      <p class="attr">背景设置</p>
      <div class="adjust-item">
        <span>组件背景</span>
        <el-radio-group v-model="config.pageConfig.cptType">
          <el-radio label="1">背景色</el-radio>
          <el-radio label="2">背景图</el-radio>
        </el-radio-group>
      </div>

      <div class="adjust-item" v-show="config.pageConfig.cptType == 1">
        <span></span>
        <el-color-picker v-model="config.pageConfig.bgColor" />
        <span class="color-value">{{ config.pageConfig.bgColor }}</span>
      </div>
      <div class="add-item-input" v-show="config.pageConfig.cptType == 2">
        <p></p>
        <h4>建议图片宽度355px，高度120px</h4>
        <div class="upload-img" v-if="config.pageConfig.bgImg">
          <el-image style="width: 100%; height: 100%" :src="config.pageConfig.bgImg" fit="contain"></el-image>
          <div class="upload-img_cover">
            <Upload :model-value="fileList" file-path="act/" :limit="999" :show-file-list="false"
              @success="uploadSuccess">
              <el-button size="small" @click="currentType = 'bgImg'">替换</el-button>
            </Upload>
          </div>
        </div>
        <Upload v-else v-model="config.pageConfig.bgImg" file-path="act/" list-type="picture-card">
          <el-icon>
            <Plus />
          </el-icon>
        </Upload>
      </div>
    </div>

    <div class="divider"></div>
    <div class="func">
      <p class="attr">外边距</p>
      <div class="adjust-item">
        <span>上边距</span>
        <el-slider v-model="config.pageConfig.marginTop" :min="0" :max="50" show-input size="small" />px
      </div>
      <div class="adjust-item">
        <span>下边距</span>
        <el-slider v-model="config.pageConfig.marginBottom" :min="0" :max="50" show-input size="small" />px
      </div>
      <div class="adjust-item">
        <span>左右边距</span>
        <el-slider v-model="config.pageConfig.margin" :min="0" :max="50" show-input size="small" />px
      </div>
    </div>
    <div class="func">
      <p class="attr">内边距</p>
      <div class="adjust-item">
        <span>上边距</span>
        <el-slider v-model="config.pageConfig.paddingTop" :min="0" :max="200" show-input size="small" />px
      </div>
      <div class="adjust-item">
        <span>左边距</span>
        <el-slider v-model="config.pageConfig.paddingLeft" :min="0" :max="200" show-input size="small" />px
      </div>
      <div class="adjust-item">
        <span>右边距</span>
        <el-slider v-model="config.pageConfig.paddingRight" :min="0" :max="200" show-input size="small" />px
      </div>
      <div class="adjust-item">
        <span>下边距</span>
        <el-slider v-model="config.pageConfig.paddingBottom" :min="0" :max="300" show-input size="small" />px
      </div>
    </div>
    <div class="divider"></div>
    <div class="func">
      <p class="attr">圆角设置</p>
      <div class="adjust-item">
        <span>上圆角</span>
        <el-slider :min="0" :max="20" v-model="config.pageConfig.radiusTop" show-input size="small" />px
      </div>
      <div class="adjust-item">
        <span>下圆角</span>
        <el-slider :min="0" :max="20" v-model="config.pageConfig.radiusBottom" show-input size="small" />px
      </div>
    </div>
    <div class="divider"></div>

    <href-selector v-model:show="linkFormVisible" :model-value="linkObject" @confirm="confirmLink" />
  </div>
</template>

<script lang="ts">
export default {
  name: "IntegralOperation",
};
</script>
<script lang="ts" setup>
import { useHrefSelector } from "@/views/activity/actApp/components/default/compositions/useHrefSelector";
import TitleIcon from "@/assets/app/icon/integral.png";
import OperationTitle
  from "@/views/activity/actApp/components/default/operationComponents/operationTitle/OperationTitle.vue";

const config = defineProps({
  pageConfig: {
    type: Object,
    default: {
      showType: "1", // 积分展示类型
      integralSize: 24, // 积分字号
      integralColor: "#FFFFFF", // 积分颜色
      showIntegralRule: "1", // 积分规则是否显示
      imgIntegralRule: "", // 积分规则图片
      cptType: "2", // 组件类型
      bgColor: "#FFFFFF", // 背景色
      bgImg: "", // 背景图
      marginTop: 10,
      marginBottom: 10,
      margin: 10,
      paddingTop: 16,
      paddingLeft: 24,
      paddingRight: 12,
      paddingBottom: 0,
      radiusTop: 0,
      radiusBottom: 0,
      openToLink: false,
      url: "",
      urlName: "",
    },
  },
});

const { linkFormVisible, linkIndex, linkObject, submitUrl, linkDialog } =
  useHrefSelector();

const currentType = ref("");
const fileList = ref([]);
const uploadSuccess = (value: any) => {
  config.pageConfig[currentType.value] = value.url;
};
let emits = defineEmits<{ (e: "changeStyle", configStyle: Object): void }>();

watch(config.pageConfig, (val) => {
  emits("changeStyle", config.pageConfig);
});

const confirmLink = (link: any) => {
  config.pageConfig.url = link.url;
  config.pageConfig.urlName = link.urlName;
};
</script>

<style lang="scss" scoped>
.title {
  padding: 8px 23px;
  overflow: hidden;
  // border-bottom: 5px solid #f6f7f9;
  display: flex;
  position: relative;
  height: 50px;
  box-sizing: border-box;

  img {
    position: absolute;
    left: 0;
    top: -5px;
  }

  h5 {
    font-size: 16px;
    font-weight: 700;
    position: absolute;
    left: 70px;
    top: 0;
    line-height: 50px;
  }
}

.divider {
  border-bottom: 5px solid #f6f7f9;
}

.func {
  // border-bottom: 5px solid #f6f7f9;
  padding: 20px 16px;
  font-size: 16px;

  .color-value {
    display: inline-block;
    width: 200px;
    text-align: left;
    margin-left: 5px;
  }

  .attr {
    line-height: 1;
    color: #47565d;
    font-weight: bolder;
    margin-bottom: 20px;
  }

  ul.common-ul {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;

    li {
      flex: 1;
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px 0 0 4px;
      border: 2px solid #ededed;
      border-collapse: collapse;

      &.active {
        border: 2px solid #fb6638;
      }

      img {
        max-width: 100% !important;
        max-height: 100% !important;
      }
    }
  }

  h4 {
    position: relative;
    padding: 8px 16px 8px 16px;
    border-radius: 6px;
    color: red;
    font-size: 16px;
    font-weight: 600;
    line-height: 22px;
    margin-bottom: 10px;
    border: 1px solid #d8e8fc;
    background-color: #e5f0fe;
    width: 170px;
    margin-right: 10px;
    margin-top: 10px;
  }

  div.adjust-item {
    display: flex;
    align-items: center;
    margin-top: 3px;
    margin-bottom: 10px;

    .link-div {
      width: calc(100% - 80px);
      display: flex;
      margin-left: 84px;
      align-items: center;
      background: #e8effc;
      border: 0;
      padding: 8px 0 8px 16px;
      cursor: pointer;
      position: relative;

      :deep(.el-icon) {
        margin-right: 10px;
      }

      :deep(.el-input) {
        font-size: 12px;
        height: 30px;
        width: calc(100% - 30px);
      }

      .close-btn {
        position: absolute;
        right: 5px;
      }
    }

    span {
      width: 70px;
      text-align: right;
      margin-right: 15px;
      color: #666;
    }

    :deep(.el-slider) {
      width: 240px;
      margin-right: 3px;
      margin-left: 15px;
    }

    :deep(.el-slider__runway.show-input) {
      margin-right: 15px;
    }

    :deep(.el-input-number) {
      width: 100px;
      background: #f4f3f7;
      border: 1px solid #f4f3f7;
    }
  }

  .add-item {
    width: 100%;

    li {
      background: #f4f3f7;
      border-radius: 4px;
      padding: 10px 20px 10px 10px;
      color: #999;
      margin-top: 10px;
      margin-bottom: 20px;
      position: relative;
      display: flex;

      &.extra-li {
        justify-content: center;
      }

      .upload-img {
        width: 62px;
        height: 62px;
        margin-right: 10px;
        position: relative;

        :deep(.el-image) {
          width: 62px;
          height: 62px;
        }

        &:hover {
          .upload-img_cover {
            opacity: 1;
          }
        }

        .upload-img_cover {
          opacity: 0;
          position: absolute;
          transition: all 0.3s ease;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background-color: rgba(0, 0, 0, 0.7);
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: space-evenly;
        }
      }

      :deep(.el-upload-list) {
        width: 62px;
        height: 62px;
        margin-right: 10px;
      }

      :deep(.el-upload--picture-card) {
        width: 62px;
        height: 62px;
      }

      // img {
      //   width: 50px;
      //   height: 50px;
      //   line-height: 50px;
      //   margin-right: 10px;
      //   border: 1px dashed #ededed;
      //   text-align: center;
      //   color: #dad9d9;
      //   background-size: 100% 100%;
      //   background-repeat: no-repeat;
      //   float: left;
      //   position: relative;
      // }
      div.link-div {
        width: calc(100% - 80px);
        display: flex;
        align-items: center;
        background: #e8effc;
        border: 0;
        padding-left: 16px;
        cursor: pointer;
        position: relative;

        :deep(.el-icon) {
          margin-right: 10px;
        }

        :deep(.el-input) {
          font-size: 12px;
          height: 30px;
          width: calc(100% - 30px);
        }

        .close-btn {
          position: absolute;
          right: 5px;
        }
      }

      .sure-close {
        position: absolute;
        right: 5px;
        top: 5px;
        cursor: pointer;
      }
    }
  }
}

.add-item-input {
  display: flex;
  align-items: center;
  margin-bottom: 20px;

  >p {
    width: 77px;
    text-align: right;
    margin-right: 8px;
  }

  .upload-img {
    width: 62px;
    height: 62px;
    margin-right: 10px;
    position: relative;

    :deep(.el-image) {
      width: 62px;
      height: 62px;
    }

    &:hover {
      .upload-img_cover {
        opacity: 1;
      }
    }

    .upload-img_cover {
      opacity: 0;
      position: absolute;
      transition: all 0.3s ease;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.7);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-evenly;
    }
  }

  :deep(.el-upload-list) {
    width: 62px;
    height: 62px;
    margin-right: 10px;
  }

  :deep(.el-upload--picture-card) {
    width: 62px;
    height: 62px;
  }

  // img {
  //   width: 40px;
  //   height: 40px;
  // }
  :deep(.el-color-picker) {
    margin-right: 10px;
  }
}
</style>
